﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

/// <summary>
/// Summary description for Company
/// </summary>
public class Company
{
  private const string SP = "Company_GetById";
  private const string SP2 = "Company_GetIdByName";

  DatabaseManager db;
  MySqlDataReader reader;

  public string Id { get; set; }
  public string Name { get; set; }
  public string Country { get; set; }

  public Company()
  {
    db = new DatabaseManager();
  }

  public void Load(string id)
  {
    db.AddParameter("@id", id);
    using (reader = db.ExecuteStoredProcedure(SP))
    {
      while (reader.Read())
      {
        Id = reader["id"].ToString();
        Name = reader["name"].ToString();
        Country = reader["country"].ToString();
      }
    }
  }

  public void GetCompanyIdByName(string name)
  {
    db.AddParameter("@_name", name);
    using (reader = db.ExecuteStoredProcedure(SP2))
    {
      while (reader.Read())
      {
        Id = reader["id"].ToString();
      }
    }
  }
}